<template>
    <el-main>
        <el-table :data="tableData">
        <el-table-column prop="code" label="商品编号">
        </el-table-column>
        <el-table-column prop="name" label="商品名称">
        </el-table-column>
        <el-table-column prop="model" label="型号">
        </el-table-column>
         <el-table-column prop="unit" label="单位">
        </el-table-column>
        <el-table-column prop="lastPurchasingPrice" label="上次进价">
        </el-table-column>
        <el-table-column prop="inventoryQuantity" label="库存数量">
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
        <el-button size="small" type="text" @click="handleAdd(scope.row)">添加</el-button>
        </template>
      </el-table-column>
      </el-table>
       <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
  </div>
    </el-main>
</template>
<script>
export default {
    data(){
        return {
           tableData:[],
           currentPage:1,
           pageSizes:[1, 2, 3, 4,5],
           pageSize:5,
           total:5,
           dialogVisible:false,
           form: {
             userName: [
               {required:true,message:'用户名不能为空',trigger:'blur'}
             ],
             code:'',
             name:'',
             model:'',
             unit:'',
             lastPurchasingPrice:'',
             inventoryQuantity:''
             },
        }
    },mounted(){
      this.requestData();
  },methods:{
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
         this.requestData();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        this.requestData();

      },
   requestData(){
      var api = "http://localhost:8089/admin/goods/lists";
      var params = {
        pageNum:this.currentPage,
        pageSize:this.pageSize
      }
      this.$http.get(api,{params:params}).then(response=>{
        console.log(response);
        this.tableData = response.body.tableData;
        this.total=response.body.total;
      });
   },handleAdd(row){
     alert(row.id);
     this.$router.push({name:'/toAdd',params:{id:row.id}});
    }
 } 
}
</script>

